<#import "/spring.ftl" as s/>
<@override name="main">
<div id='QuestionForm'>
	<form id='form_question' action="<@s.url '/issue/visitor/save'/>" method="post" enctype="multipart/form-data" autocomplete="off" >
		<table art="form" columns="90,*" autoLabel="true" rightAlign="true" colon="true" width="800px">
			<input type="hidden" id="p_id" name="pid" value="${project.id}">
			<tr>
				<td>
					<label for="qa_project" art='label' required="true"><@s.message "issue.project.visitor.project"/></label>
				</td>
				<td>
					<a id="qa_project" class='qa_project selected' title='<@s.message 'issue.project.visitor.tip.project'/>'>${project.name}</a>
				</td>
			</tr>
			<tr>
				<td>
					<label for="txt_title" art='label' required="true"><@s.message "issue.project.visitor.title"/></label>
				</td>
				<td>
					<input tabindex='1' id='txt_title'  type="text" art="textbox"   requiredMsg="<@s.message "issue.new.title.required.error.tip"/>"
						   required="true" validType="length[5,255]"  display="right"   errorMsg="<@s.message "issue.new.login.title.error.tip"/>"
						   emptyText="<@s.message 'issue.project.visitor.tip.title'/>" name='summary'/>
				</td>
			</tr>
			<tr>
				<td>
					<label art='label' required="true"><@s.message "issue.project.visitor.type"/></label>
				</td>
				<td id="radio_select">
					<#list types as type>
						<#if type_index==0>
							<input type="radio" name="issuetype" id="issue_type_${type.id}" value="${type.id}" title="${type.description}"
								   checked="true" tabindex="2">
							<label for="issue_type_${type.id}">${type.pname}</label>
						<#else>
							<input type="radio" id="issue_type_${type.id}" name="issuetype" value="${type.id}" title="${type.description}" tabindex="2">
                            <label for="issue_type_${type.id}">${type.pname}</label>
						</#if>
					</#list>
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<strong><@s.message 'issue.project.visitor.desciption'/><@s.message 'colon'/></strong><@s.message 'issue.project.visitor.tip.description'/>
					<textarea tabindex='2' name="description" id="ta_qa_content" style="height:260px;"></textarea>
				</td>
			</tr>
			<tr>
				<td>
					<label for="tx_reporter_login" art='label'><@s.message "issue.project.visitor.reporter_login"/></label>
				</td>
				<td>
					<input tabindex='3' id='tx_reporter_login'  type="text" art="textbox"
						   emptyText="<@s.message 'issue.project.visitor.tip.reporter_login'/>" name='reporter_login'/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="tx_reporter" art='label'><@s.message "issue.project.visitor.reporter"/></label>
				</td>
				<td>
					<input tabindex='3' id='tx_reporter'  type="text" art="textbox"
						   emptyText="<@s.message 'issue.project.visitor.tip.reporter'/>" name='reporter'/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="tx_mail" art='label'><@s.message "issue.project.visitor.mail"/></label>
				</td>
				<td>
					<input tabindex='4' id='tx_mail'  type="text" art="textbox"  validType="email"   errorMsg="<@s.message"issue.project.visitor.email.illegalTip"/>"
						   emptyText="<@s.message 'issue.project.visitor.tip.mail'/>" name='reporterMail'/>
					<input type="checkbox" tabindex="5" id="reporter_notify" name="mail_notify" disabled="true">
					<label for="reporter_notify"><@s.message 'issue.project.visitor.mail.notify'/></label>
				</td>
			</tr>
			<tr>
				<td id="add_br">
					<label art='label'><@s.message "issue.project.visitor.attachement"/></label>
				</td>
				<td id="file">
			</td>
			</tr>
            <tr>
                <td>

                </td>
                <td>
                    <div> <a id="add_attach" name="add_" style="cursor: pointer"  onclick="issue_add_visitor.add_more()"><@s.message "issue.project.visitor.attachement.more"/></a>&nbsp;<span><@s.message 'issue.project.visitor.attachment.size'/></span></div>
                </td>
            </tr>
			<tr id='tr_form_msg'>
				<td colspan="2"></td>
			</tr>
			<tr>
				<td></td>
				<td>
					<button id="btn_submit" type="submit" tabindex="7">
						<span><span><@s.message 'issue.project.visitor.button1'/> &raquo;</span></span>
					</button>
				</td>
			</tr>
		</table>
	</form>
</div>
<div id='QuestionTip'>
	<div id='QuestionTitleTip'>
		<h2><@s.message 'issue.project.visitor.read'/></h2>
		<ol>
			<#list 1..4 as i>
				<li><@s.message 'issue.project.visitor.read.${i}'/></li>
			</#list>
		</ol>
	</div>
</div>
<script type="text/javascript" src="<@s.url '/resources/common/ke/kindeditor-min.js'/>" charset="utf-8"></script>
<script type='text/javascript'>
	<!--
	var editor;
	KindEditor.ready(function (K) {
		editor = K.create('#ta_qa_content', {
			resizeType           :1,
			urlType              :'domain',
			tabIndex             :2,
			width                :540,
			shadowMode           :false,
			allowPreviewEmoticons:false,
			allowImageUpload     :true,
			allowFlashUpload     :false,
			uploadJson           :'<@s.url '/action/upload'/>',
			afterCreate          :function () {
				K.ctrl(this.edit.iframe.get(0).contentWindow.document, 13, function () {
					$("#ta_qa_content").parent().submit();
				});
			},
			afterChange          :function () {
				this.sync();
			},
			items                :['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'image', 'link', '|', 'about']
		});
            editor.html(language.issue.issue_tip_template.error);
	});

	$(document).ready(function () {

        var createobj_input=$('<input name="attachment" type="file"/>');
        var createobj_br=$('</br>');
        var createobj_del=$('<input type="button" value="删除"/>');

        $('#file').append(createobj_br);
        $('#file').append(createobj_input);
        $('#file').append(createobj_del);

        createobj_del.click(function(){
            var  visitor_att_count=0;
            $("#file").find(":file").each(function()
            {
                visitor_att_count+=1;
            })
            if(visitor_att_count<=1)
            {
                createobj_input.attr("value","");
                return ;
            }
            else{
                createobj_input.remove();
                createobj_br.remove();
                createobj_del.remove();
            }
        })
        createobj_input.change(function(){
            if ($.browser.ie) {

            } else {
                file_size = this.files[0].size;
                console.log(file_size/1024/1024 + "MB");

                var size = file_size / 1024;
                if(size > 10240){
                    alert("上传的文件大小不能超过10M！");
                    this.value="";
                    var num01 = file_size/1024;
                    num02 = num01.toFixed(2) ;
                }else{
                    var num01 = file_size/1024;
                    num02 = num01.toFixed(2) ;
                }
            }
            return true;
        })

		$('#form_question').ajaxForm({
			dataType       :'json',
			beforeSerialize:function ($form, options) {
                alert(editor.html())
                editor.html(decodeURIComponent(editor.html()));
                alert(editor.html())
				editor.sync();
			},
			beforeSubmit   :function () {
				if (!$.isValid()) {
					return false;
				}

				if (editor.html().length < 1) {
					cdms.common.show_error('tr_form_msg', language.issue.issue_content_empty);
					return false;
				}

				$('#btn_submit').attr('disabled', 'disabled');
				cdms.common.show_info('tr_form_msg', language.issue.submit_wating_msg);
			},
			success        :function (json) {
                location.reload();
                $('#btn_submit').removeAttr('disabled');
				if (json.type) {
					alert(json.msg);
					$('#tr_form_msg').hide();
					$('#form_question').resetForm();
					editor.html("");
                     location.reload();
				} else {
					cdms.common.show_error('tr_form_msg', json.msg);
				}
			}
		});
		 var tx_mail = $('#tx_mail');
        tx_mail.bind('propertychange',visitor.activation_notify);
        tx_mail.bind('blur',visitor.activation_notify);
        $("#radio_select").click(function(){
            if($('input[id=issue_type_1]:checked').size()!=0){
                editor.html(language.issue.issue_tip_template.error);
            }
            if($('input[id=issue_type_2]:checked').size()!=0){
                editor.html(language.issue.issue_tip_template.demand);
            }
            if($('input[id=issue_type_3]:checked').size()!=0){
                editor.html(language.issue.issue_tip_template.proposal);
            }
            if($('input[id=issue_type_4]:checked').size()!=0) {
                editor.html(language.issue.issue_tip_template.other);
            }
        }) ;
	});

	window.onbeforeunload = function () {
		var atitle = $('#txt_title').val();
		if (atitle.length == 0 || atitle == '<@s.message 'issue.project.visitor.tip.title'/>') {
			var abody = editor.html();
			if (abody.length == 0)
				return;
		}
		return language.issue.abort_issue_msg;
	};
	//-->
</script>

<script type="text/javascript" src="<@s.url '/resources/scripts/issue/visitor.js'/>" charset="utf-8"></script>
</@override>
<@extends name="/common/layout.ftl" current="new_issue" title="issue.visitor.add"></@extends>